<?php
require 'init.php';
extract($_POST);
$isEdit = $db -> query("SELECT * FROM `newsinfo` WHERE `id` = '$id' AND `admin` = '$admin'") -> fetch_assoc();
if(is_null($isEdit)){
    echo json_encode([
        'code'=>201,
        'msg'=>'编辑失败'
    ]);
}else{
    if(count($_FILES)){
        $name = rand(1,9999).$_FILES['image']['name'];
        move_uploaded_file($_FILES['image']['tmp_name'], '../img/'.$name);
        $db -> query("UPDATE `newsinfo` SET `news_title` = '$title' , `image`='./img/$name' , `news_desc` = '$desc' , `news_content` = '$content' , `news_press` = '$press' , `author` = '$author' WHERE `id` = '$id' AND `admin` = '$admin'");
    }else{
        $db -> query("UPDATE `newsinfo` SET `news_title` = '$title' , `image`=`image`, `news_desc` = '$desc' , `news_content` = '$content' , `news_press` = '$press' , `author` = '$author' WHERE `id` = '$id' AND `admin` = '$admin'");
    }
    echo json_encode([
        'code'=>200,
        'msg'=>'修改成功',
    ]);
}


?>